<style>
    #teachProgram-addNew {
        padding: 20px 25px 25px 0;
    }
</style>
<div class="layui-fluid" id="teachProgram-addNew">
    <form class="layui-form" action="" lay-filter="teachProgram-addNew-form" id="teachProgramForm_addNew">
        <div class="layui-form-item">
            <label class="layui-form-label  febs-form-item-require">批次：</label>
            <div class="layui-input-inline">
                <select name="batchId" id="cboBatch_TeachProgram_addNew" lay-filter="cboBatch_TeachProgram_addNew">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">院校：</label>
            <div class="layui-input-inline">
                <select name="collegeId" id="college_TeachProgram_addNew" lay-filter="college_TeachProgram_addNew">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">层次：</label>
            <div class="layui-input-inline">
                <select name="levelId" id="cboLevel_TeachProgram_addNew" lay-filter="cboLevel_TeachProgram_addNew" >
                    <option value="">请选择</option>
                    <option value="1">专升本</option>
                    <option value="2">高起本</option>
                    <option value="3">高起专</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label febs-form-item-require" >类别：</label>
                <div class="layui-input-inline">
                    <select name="typeId" id="cboType_TeachProgram_addNew" lay-filter="cboType_TeachProgram_addNew">

                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">专业：</label>
            <div class="layui-input-inline">
                <select name="majorId" id="cboMajor_TeachProgram_addNew" lay-filter="cboMajor_TeachProgram_addNew">

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">方式：</label>
            <div class="layui-input-inline">
                <select name="modeId" id="cboMode_TeachProgram_addNew" lay-filter="cboMode_TeachProgram_addNew" >
                    <option value="">请选择</option>
                    <option value="4">函授</option>
                    <option value="5">业余</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">学制：</label>
            <div class="layui-input-inline">
                <select name="schoolingId" id="cboSchool_TeachProgram_addNew" lay-filter="cboSchool_TeachProgram_addNew" >

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">学年：</label>
            <div class="layui-input-inline">
                <select name="absoYearId" id="cboYear_TeachProgram_addNew" lay-filter="cboYear_TeachProgram_addNew">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">学期：</label>
            <div class="layui-input-inline">
                <select name="absoSemId" id="cboTerm_TeachProgram_addNew" lay-filter="cboTerm_TeachProgram_addNew" autocomplete="off">

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">课程名称：</label>
            <div class="layui-input-block">
                <input type="text" name="courseName" minlength="2" maxlength="15" lay-verify="range|name"
                       autocomplete="off" class="layui-input" placeholder="请输入课程名称">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="teachProgram-addNew-form-submit" id="submit"></button>
        </div>
    </form>
</div>

<script data-th-inline="javascript">
    layui.use(['febs', 'form','xmSelect',  'validate'], function () {
        let $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            form = layui.form,
            xmSelect = layui.xmSelect,
            eamXmSelect,
            majorSelect,

            teachProgram = [[${teachProgram}]],
            validate = layui.validate;

        form.verify(validate);
        form.render();

//        initTeachProgramValue();

        initCollege();
        function initCollege() {
            $.ajax({
                type: 'get',
                url: 'homework/collegeList',
                success: function (res) {
                    var str = '<option value=\'\'>请选择</option>';
                    layui.each(res.data, function (index, item) {
                        str = str + "<option value='" + this.id + "'>" + this.name + "</option>"
                    });
                    $("#college_TeachProgram_addNew").append(str);
                    //渲染select
                    form.render('select');
                }
            })
        }

        initMajor();
        function initMajor() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/majorList',
                success: function (res) {
                    var str = '<option value=\'\'>请选择</option>';
                    layui.each(res.data, function (index, item) {
                        str = str + "<option value='" + this.id + "'>" + this.fullName + "</option>"
                    });
                    $("#cboMajor_TeachProgram_addNew").append(str);
                    //渲染select
                    form.render('select');
                }
            })
        }

        //类别下拉框
        initSubject();
        function initSubject() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/subjectCategoryList',
                success: function (res) {
                    var str = '<option value=\'\'>请选择</option>';
                    layui.each(res.data, function (index, item) {
                        str = str + "<option value='" + this.id + "'>" + this.fullName + "</option>"
                    });
                    $("#cboType_TeachProgram_addNew").append(str);
                    //渲染select
                    form.render('select');
                }
            })
        }
        form.on("select(cboSchool_TeachProgram_addNew)", function (obj) {
            var absoYearId = $('#cboSchool_TeachProgram_addNew').val();
            if(absoYearId==59){
                initYear();
            }else if(absoYearId==58){
                initYear2();
            }
            form.render('select');

        });
        function initYear2() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/yearList',
                success: function (res) {
                    var str = '<option value=\'\'>请选择</option>';
                    for(var i = 0; i < 3; i++){
                        str = str +"<option value='" + res.data[i].id + "'>" + res.data[i].yearName + "</option>";
                    }
                    $("#cboYear_TeachProgram_addNew").empty();
                    $("#cboYear_TeachProgram_addNew").html(str);
                    //渲染select
                    form.render('select');
                }
            })
        }

        //批次下拉框遍历
        $(function () {
            $.get("teachProgram/batchList", function (obj) {
                // selectIDc=obj.data;
                var str="<option value=''>请选择</option>";
                layui.each (obj.data, function (index, item) {
                    str=str+"<option value='" + this.id + "'>" + this.batchName + "</option>";

                });

                $ ("#cboBatch_TeachProgram_addNew"). html(str);
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            });
        });
        function initYear() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/yearList',
                success: function (res) {
                    $("#cboYear_TeachProgram_addNew").empty();
                    $("#cboYear_TeachProgram_addNew").append("<option value=''>请选择</option>");
                    layui.each(res.data, function (index, item) {
                        $("#cboYear_TeachProgram_addNew").append("<option value='" + this.id + "'>" + this.yearName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }


        form.on("select(cboLevel_TeachProgram_addNew)", function (obj) {
            var levelId = $('#cboLevel_TeachProgram_addNew').val();
            if(levelId==2){
                $("#cboSchool_TeachProgram_addNew").empty();
                $("#cboSchool_TeachProgram_addNew").append("<option value=''>请选择</option>");
                $("#cboSchool_TeachProgram_addNew").append("<option value='59'>5年</option>");
            }else {
                $("#cboSchool_TeachProgram_addNew").empty();
                $("#cboSchool_TeachProgram_addNew").append("<option value=''>请选择</option>");
                $("#cboSchool_TeachProgram_addNew").append("<option value='58'>2.5年</option>");
            }
            form.render('select');
        });

        $(function () {
            var levelId = $('#cboLevel_TeachProgram_addNew').val();
            if(levelId==2){
                $("#cboSchool_TeachProgram_addNew").empty();
                $("#cboSchool_TeachProgram_addNew").append("<option value=''>请选择</option>");
                $("#cboSchool_TeachProgram_addNew").append("<option value='59'>5年</option>");
            }else {
                $("#cboSchool_TeachProgram_addNew").empty();
                $("#cboSchool_TeachProgram_addNew").append("<option value=''>请选择</option>");
                $("#cboSchool_TeachProgram_addNew").append("<option value='58'>2.5年</option>");
            }
            form.render('select');
        });

        form.on("select(cboYear_TeachProgram_addNew)", function (obj) {
            var absoYearId = obj.value;
            initTerm(absoYearId);
        });

        //学期下拉框
        function initTerm(id) {
            $.ajax({
                type: 'get',
                url: 'teachProgram/termList',
                data: {absoYearId: id},
                success: function (res) {
                    $("#cboTerm_TeachProgram_addNew").empty();
                    layui.each(res.data, function (index, item) {
                        $("#cboTerm_TeachProgram_addNew").append("<option value='" + this.id + "'>" + this.semesterName + "</option>");
                    });
                    //渲染select
                    form.render('select');
                }
            })
        }


        form.on('submit(teachProgram-addNew-form-submit)', function (data) {
            console.log(data.field)
            console.log(teachProgram)

            febs.get(ctx + 'teachProgram/addNew', data.field, function () {
                layer.closeAll();
                febs.alert.success('教学计划增加成功');
                $('#businesses-teachProgram').find('#query').click();            });
            return false;
        });
    });

</script>